package com.apes.scm.masterdata.party.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.scm.masterdata.party.model.Party;
import com.apes.scm.masterdata.party.model.PartyRole;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Set;


public interface CompanyRepository extends CustomRepository<Party, Long> {
    @Query("SELECT T FROM Party T JOIN T.partyRoles S WHERE S.role.id = :rolId")
    Page<Party> find(@Param("rolId") String rolId,  Pageable pageable);

    Page<Party> findByPartyRolesIn(Set<PartyRole> partyRoles,  Pageable pageable);

    @Modifying
    @Query("UPDATE Party SET NAME = ?2 WHERE id = ?1")
    int updatePartyNameById(String id, String nName);

    long countById(String id);
}
